var oEditors = [];

$(document).ready(function(){
	$('.add').hide();
	$(".header").load("header.html");$(".footer").load("footer.html"); 
	
	

	
	  nhn.husky.EZCreator.createInIFrame({
	    oAppRef: oEditors,
	    elPlaceHolder: "textarea1",
	    sSkinURI: "../se2/SmartEditor2Skin.html",        
	    fCreator: "createSEditor2"

	  })
	  
})
function add(){
	$('.add').show();
}
function add_exit(){
	$('.add').hide();
}


  
  var myModule = angular.module('myModule', []);
  
  
  
  myModule.controller('MyController', function ($scope, $http,$location) {
      $scope.items =null;
      $scope.reply = null;
      $scope.id='';
      $scope.writeReply={};
      $scope.modifyReply={};
      $scope.user={};
      
      $scope.subject=null;
      $scope.modify=false;
      
      $scope.selectedIndex=-1;

      $scope.loadData = function() {
          myUtil.onHttp($http, 'get', 'user.do', null, null, function(data){$scope.id=data;});
          
    	  myUtil.onHttp($http, 'get', 'content.do', {content_id:$location.search().content_id}, null, 
    			  function(data) {
    		  		$scope.items=data.content; $scope.reply =data.reply; $scope.subject=data.subject;
    		  		myUtil.onHttp($http,'get','userAuthority.do',null,null,function(data){$scope.user=data; if($scope.user.authority=="ROLE_ADMIN" && $scope.items.notice==0){ $('div.comment').css('display','block'); $('h1.answer').css('display','inline-block')}});
    		  	} )
    	  
      }

      $scope.list = function(){
    	  location.href='QnA.html#?pg='+$location.search().pg+"&title="+$location.search().title+"&search="+$location.search().search;
    	  
      }
      
      $scope.replyWrite = function(){
    	  oEditors.getById["textarea1"].exec("UPDATE_CONTENTS_FIELD", []);
      	  $scope.writeReply.content = $('#textarea1').val();
      	
    	  $scope.writeReply.content_id=$location.search().content_id;
    	  $scope.writeReply.id=$scope.id;
    	 
    	  
    	  myUtil.onHttp($http, 'post', 'replyWrite.do',null,$scope.writeReply,function(){$scope.loadData(); $scope.writeReply.content=''});
      }
      
      $scope.replyDelete = function(index){
    	  
    	  myUtil.onHttp($http, 'post', 'replyDelete.do',{reply_id : $scope.reply[index].reply_id , content_id:$location.search().content_id},null, $scope.loadData);
      }
      
      $scope.modify =function(index,content){
    	  $scope.selectedIndex=index;
    	  $scope.modifyReply.content=content;
      }
      
      $scope.init=function(){
    	  $scope.selectedIndex=-1;
      }
      
      $scope.replyModify=function(reply_id){
    	  $scope.modifyReply.reply_id=reply_id;
    	  myUtil.onHttp($http, 'post', 'replyModify.do',null,$scope.modifyReply,function(){$scope.loadData(); $scope.modifyReply.content=''; $scope.selectedIndex=-1; });
      }
      
     

      $scope.loadData();        
  });